var crud_url = 'crud.ftl';

function scroll(obj, h, s){
    if(obj == undefined){return false;}
    var h = h || 200;
    var s = s || 1.2;
    var obj = typeof(obj)=="string"?document.getElementById(obj):obj;
    var status = obj.getAttribute("status")==null;
    var oh = parseInt(obj.offsetHeight);
    obj.style.height = oh;
    obj.style.display = "block";
 	obj.style.overflow = "hidden";
    if(obj.getAttribute("oldHeight") == null){
        obj.setAttribute("oldHeight", oh);
    }else{
        var oldH = Math.ceil(obj.getAttribute("oldHeight"));
    }
    var reSet = function(){
        if(status){
            if(oh < h){
                oh = Math.ceil(h-(h-oh)/s);
                obj.style.height = oh+"px";
            }else{
                obj.setAttribute("status",false);
                window.clearInterval(IntervalId);
            }
        }else{
            obj.style.height = oldH+"px";
            obj.removeAttribute("status");
            window.clearInterval(IntervalId);
        }
    }
    var IntervalId = window.setInterval(reSet,10);
 	return status;
};

function lookup(url, inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.get(url, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
};
	
function fill(objId, thisValue) {
	$('#' + objId).val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
};

function go_add_page(model_name) {
	documnet.location.href=crud_url + "?model=" + model_name + "&opt=addform";
};

function check_unique(model_url, field_n, field_obj) {
	$.ajax({
		type: "POST",
		url: crud_url,
		data: "model=" + model_url + "&opt=checkunique&u_" + field_n + "=" + field_obj.value,
		success: 
			function(txt){
				if(txt == 1){
					alert(field_obj.value + '已经存在，请换其他。');
				}else{
				}
			}
	}); 
};
	